package thread;

public class DaemonThreadDemo {
    public static void main(String[] args) {
        Thread rose = new Thread(){
            public void run(){
                for (int i = 0;i < 5;i++){
                    System.out.println("rose:let me go!");
                    try {
                        Thread.sleep(1000);
                    } catch (InterruptedException e) {
                    }
                }
                System.out.println("rose:aaaaa");
                System.out.println("扑通");
            }
        };

        Thread jack = new Thread(){
            public void run(){
                while (true){
                    System.out.println("jack:you jump!I jump!");
                    try {
                        Thread.sleep(1000);
                    } catch (InterruptedException e) {
                    }
                }
            }
        };
        rose.start();
        jack.setDaemon(true);//设置守护线程必须在线程启动前进行
        jack.start();
        /*
           主线程也是普通线程,如果执行了下面的代码,意味着主线程不会结束,那么就算rose结束了,jack也不会被进程杀掉.
         */
        while (true);
    }
}
